.text

main:		//instr 0	
				jal SuperGarbage
				halt
SuperGarbage:        //$a0 = pc, $a1 = *mem	//instr 2
While:         		 //instr 2
                //struct inst *instruction = &(mem[pc]);
                move $t0, $a1        //t0 = a1         
                add $t0, $a0        //t0 = a0+a1 = &(mem[pc])
                
                
                lw $s0, 0($t0)             //int op = instruction->op;
                lw $s1, 1($t0)             //int srcA = instruction->srcA;
                lw $s2, 2($t0)             //int srcB = instruction->srcB;
                lw $t6, 3($t0)         //int dest = instruction->dest;
                
                addi $a0, 0x4         //pc = pc + 4                
				
                addLoad $s1                //t4 = & Mem[srcA]; t0 = mem[srcA]                
                addLoad $s2              //t1 = mem[srcB]; t4 = &Mem[srcB]
                addLoad $t6                //t2 = mem[dest]; t4 = &mem[dest]
				move $s1, $t4				//s1 = &mem[dest]
				//end result of these three: t0 = mem[srcA], t1 = mem[srcB], t2 = mem[dest]
                
                movei $t3, 0x3F            //t3 = -1
                
            C0:      	//instr 14  
				addBNE C1               //t3 = t3 + 1, branch if t3 != op        
                
                mov45 $t4, $t5            //t4 = t0; t5 = t1
                
                sub $t4, $t5            //mem[srcA] - mem[srcB]
                sw $t4, 0($s1)            //mem[dest] = mem[srcA] - mem[srcB]
                
                j While    //break
            C1:    		//instr 19
				addBNE C2        	//t3 = t3 + 1, branch if t3 != op
                
                srl $t4, $t0, 0x1         // mem[srcA] >> 1    (use constant for shift ops)
                sw $t4, 0($s1)            // mem[dest] = mem[srcA] >> 1
                        
                j While    //break
            C2:    			//instr 23
				addBNE C3			//t3 = t3 + 1, branch if t3 != op

                mov45 $t4, $t5            //t4 = t0; t5 = t1                
                
                nor $t4, $t5             //~(mem[srcA] | mem[srcB])                
                sw $t4, 0($s1)            // mem[dest] = ~(mem[srcA] | mem[srcB])

                j While    //break
            C3:    			//instr 28
				addBNE C4				//t3 = t3 + 1, branch if t3 != op
            
                mov45 $t4, $t5            //t4 = t0; t5 = temp = mem[srcB] = t1                
                
                add $t4, $a1            //t4 = &mem[mem[srcA]]
                lw $t6, 0($t4)             //t6 = mem[mem[srcA]]
                
                sw $t6, 0($s1)            //s1 = mem[dest] = mem[mem[srcA]] =t6              
                
                sw $t5, 0($t4)             //t6 = mem[mem[srcA]] = temp = t5
                         
                j While    //break
            C4:    			//instr 35
				addBNE C5                //t3 = t3 + 1, branch if t3 != op
                
                in	$t2, $t0						//syscall in
                sw 	$t2, 0($s1) 
                j While    //break
            C5:    			//instr 39
				addBNE C6           	//t3 = t3 + 1, branch if t3 != op
                
                out	 $t0, $t1						//syscall out
                
                j While    //break
            C6: 			//instr 42
				addBNE C7				//t3 = t3 + 1, branch if t3 != op
                
                sw $a0, 0($s1)              //mem[dest] = pc;
                
                slti $t4,$t0, 0x0 
                bne $t4, $zero, SetPC        //if (mem[srcA] < 0)  
				j While
                
        SetPC:    			//instr 47
				move $a0, $t1            //pc = mem[srcB]
                
                j While    //break
            C7: 				//instr 49
				addBNE While			//t3 = t3 + 1, branch if t3 != op
            
                move $v0, $a0     //return pc                
                jr $ra		//return, end function
                

